package com.soen341.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.soen341.dao.ProgramDao;
import com.soen341.dao.SequenceDao;
import com.soen341.model.CourseSequence;
import com.soen341.model.Program;
import com.soen341.model.SequenceMember;
import com.soen341.service.SequenceService;

//--------------------------------------------------------------------------------------------------------------------------------
/**
* Provides implementation for services around the {@link Sequence} entity.
*/
//--------------------------------------------------------------------------------------------------------------------------------
@Service("sequenceService")
public class SequenceServiceImpl implements SequenceService
{
	@Autowired
	private SequenceDao sequenceDao;

	@Autowired
	private ProgramDao programDao;

	//--------------------------------------------------------------------------------------------------------------------------------
	/**
	 * Sets the underlying SequenceDao implementation to be used by the services.
	 */
	//--------------------------------------------------------------------------------------------------------------------------------
	public void setSequenceDao(SequenceDao sequenceDao)
	{
		this.sequenceDao = sequenceDao;
	}

	// -------------------------------------------------------------------------------
	@Transactional(readOnly = true)
	public List<SequenceMember> loadByProgramId(String programId)
	{
		Program program = programDao.loadProgram(programId);
		
		return loadBySequenceId(program.getSequenceId());
	}

	// -------------------------------------------------------------------------------
	@Transactional(readOnly = true)
	public CourseSequence loadSequenceByProgramId(String programId)
	{
		Program program = programDao.loadProgram(programId);
		
		return loadSequenceBySequenceId(program.getSequenceId());
	}

	// -------------------------------------------------------------------------------
	@Transactional(readOnly = true)
	public List<SequenceMember> loadBySequenceId(String sequenceId)
	{
		List<SequenceMember> sequence = sequenceDao.loadSequenceMembers(sequenceId);
		return sequence;
	}

	// -------------------------------------------------------------------------------
	@Transactional(readOnly = true)
	public CourseSequence loadSequenceBySequenceId(String sequenceId)
	{
		CourseSequence sequence = sequenceDao.loadSequenceObject(sequenceId);
		return sequence;
	}
	
	@Transactional(readOnly = true)
	public List<Map<String,Object>> loadSemestersBySequenceId(String sequenceId)
	{		
		return sequenceDao.loadSequenceMembersBySemester(sequenceId);
	}
}
